<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ajax
 *
 * @author Administrator
 */
class ajax extends CI_Controller {

  //put your code here
  public function __construct() {
    parent::__construct();
  }

  public function list_json_city($id = '') {
    if (empty($id) && !empty($_REQUEST['id']))
      $id = $_REQUEST['id'];
    echo json_encode($this->city_model->get_all(array('state_id' => $id)));
  }

  public function get_json_city($id = '') {
    if (empty($id) && !empty($_REQUEST['id']))
      $id = $_REQUEST['id'];
    $obj = $this->city_model->get($id);
    if (!empty($obj)) {
      echo json_encode($obj);
    } else {
      echo '[]';
    }
  }

  public function list_json_state($id = '') {
    if (empty($id) && !empty($_REQUEST['id']))
      $id = $_REQUEST['id'];
    echo json_encode($this->state_model->get_all(array('country_id' => $id)));
  }

  public function get_json_state($id = '') {
    if (empty($id) && !empty($_REQUEST['id']))
      $id = $_REQUEST['id'];    
    $obj = $this->state_model->get($id);
    if (!empty($obj)) {
      echo json_encode($obj);
    } else {
      echo '[]';
    }
  }

  public function get_json_country($id = '') {
    if (empty($id) && !empty($_REQUEST['id']))
      $id = $_REQUEST['id'];
    $obj = $this->country_model->get($id);
    if (!empty($obj)) {
      echo json_encode($obj);
    } else {
      echo '[]';
    }
  }

}